package com.starlight.flower_server.infrastructure.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author yfy2001
 * @date 2023/4/9 9:27
 */
public class DataVerifyUtils {

    Pattern specialCharPattern=Pattern.compile("[~`!#$%^&*(){}:;'\"\\[\\]<>/\\\\]");
    Pattern usernamePattern = Pattern.compile("^[A-Za-z0-9]{6,12}$");
    Pattern passwordPattern=Pattern.compile("[A-Za-z0-9]{8,12}");
    Pattern eamilPattern=Pattern.compile("[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+");
    Pattern phonePattern=Pattern.compile("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$");

    public boolean isValid(String s){
        Matcher matcher=specialCharPattern.matcher(s);
        return matcher.matches();
    }

    public boolean verifyUsername(String s){
        Matcher matcher=usernamePattern.matcher(s);
        return matcher.matches();
    }

    public boolean verifyPassword(String s){
        Matcher matcher=passwordPattern.matcher(s);
        return matcher.matches();
    }

    public boolean verifyEmail(String s){
        Matcher matcher=eamilPattern.matcher(s);
        return matcher.matches();
    }

    public boolean verifyPhone(String s){
        Matcher matcher=phonePattern.matcher(s);
        return matcher.matches();
    }

}
